//read from file ,modify on char or chinese than save file

import java.io.*;
import java.util.*;

public class Main{
	public static void main(String[] args){
		try{
			File file=new File(args[0]);
			BufferedReader bufferedreader=new BufferedReader(new FileReader(file));
			CharArrayWriter chararraywriter=new CharArrayWriter();

			char[] array=new char[1];
			while(bufferedreader.read(array)!=-1){
//				System.out.print(array[0]);
				chararraywriter.write(array);
			}
			chararraywriter.close();
			bufferedreader.close();


			array=chararraywriter.toCharArray();

			System.out.println();

			for(int i=0;i<array.length;i++){
				System.out.print(array[i]);
			}
			System.out.println();

			Scanner scanner=new Scanner(System.in);
	
			System.out.print("input index:");
			int pos=scanner.nextInt();
			System.out.print("input char:");
			char ch=scanner.next().charAt(0);
			array[pos-1]=ch;

			CharArrayReader chararrayreader=new CharArrayReader(array);
			BufferedWriter bufferedwriter=new BufferedWriter(new FileWriter(file));
			char[] tmp=new char[1];
			while((chararrayreader.read(tmp))!=-1){
				bufferedwriter.write(tmp);

			}

			chararrayreader.close();
			bufferedwriter.flush();
			bufferedwriter.close();
		}
		catch(ArrayIndexOutOfBoundsException e){
			e.printStackTrace();
		}
		catch(IOException e){
			e.printStackTrace();
		}
	}
}